<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <div id="dialog-message">
 	<div id="class_room_jiandao_tabs">
		 
	</div>
 </div>
 <script>
 (function(){
	 //显示我的老师 
	 function showMsg(msg){
		 var ul=$("<ul></ul>");
		 var table_id="";
    	 for(var i=0;i<msg.list.length;i++){
    		 if(i==0){
    			 table_id = msg.list[i].table_id;
    			 
    		 }
    		 var li =$('<li id="li'+msg.list[i].table_id+'"><a href="#div'+msg.list[i].table_id+'" >'+msg.list[i].userShowName+'</a></li>');
    		  ul.append(li); 
    		  $(li).attr("table_id",msg.list[i].table_id);
    		 
    		  $(li).click(function(){
    			  loadRoomOption($(this).attr("table_id"));
    		  });
    	 }
    	 $("#class_room_jiandao_tabs").append(ul); 
    	 for(var i=0;i<msg.list.length;i++){
    		  var div=$('<div id="div'+msg.list[i].table_id+'"></div>');   		  
    		  $("#class_room_jiandao_tabs").append(div); 
    	 }  
    	 $("#class_room_jiandao_tabs").tabs(); 
    	 //加载第一个老师的教室
    	 if(table_id!=""){ 
    		 loadRoomOption(table_id);
    	 }  
	 };
	 //加载当前老师的教室位置
	 function loadRoomOption(table_id){
		 $("#div"+table_id).html("");
		 var url ="${pageContext.request.contextPath}/edu/sysClassAction.do?method=getStudent_Teacher_Room";
		 var object = new Object(); 
		 object.table_id = table_id; 
		 object.sys_class_table_id = "${param.table_id}";
		 //因为这之前的查询是把年份放在string1里面的
		 object.year = "${param.string1}"; 
		 $.ajax({
			   type: "POST",
			   url: url,
			   async:false,
			   data:object,
			   dataType:'json',
			   success: function(data){   
				if(!data ||!data.sys_Room){
						 return;
				}
				var msg =data.sys_Room; 
				 if(msg && msg.length>0 && msg[0]!=null){
					 //显示位置
					  showRoom(table_id,msg);
					 //改变位置状态
					  changRoom(table_id,data.sys_Room_Position_User);
			     }else{
			    	 $("#div"+table_id).html("目前没有可用教室!");
			     }
			   }
		}); 
	 }
	 //显示教室
	 function showRoom(table_id,msg){  
			 var chair ='<div name="chair" state="1" style="width:100px;height:70px;float:left;"><div style="width:40px;height:40px;margin-left:30px;background:url(${pageContext.request.contextPath}/image/chair2.png);"></div><div style="width:100px;height:30px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;"></div></div>';
    		 var x=msg[1];
    		 var y=msg[2]; 
    		 var  myclass_ggjs =$('<div style="margin:0 auto;text-align:center;"></div>');
    		 	myclass_ggjs.width(100*x);  
    			for(var i=0;i<x;i++){
    				for(var j=0;j<y;j++){ 
    					var b =$(chair);
    					myclass_ggjs.append(b);
    					b.attr("x1",i+1);
    					b.attr("y1",j+1); 
    					b.attr("table_id",msg[0]);
    					b.attr("startClass",msg[4]);
    					b.attr("sys_class_id",table_id);
    					
    				}
    			} 
    			var title1 =$('<div style="height:40px;float:left;text-align:center;width:100%;margin-top:30px;"><b>已过期</b></div>');
    			if(msg[3]==1){
    				title1 =$('<div style="height:40px;float:left;text-align:center;width:100%;margin-top:30px;"><b>正在使用</b></div>'); 
    			}   
    		   myclass_ggjs.append(title1); 
    		   $("#div"+table_id).append(myclass_ggjs); 
    		   selectChair(table_id);
    }
	 //改变状态
	 function changRoom(table_id,data){
		 var chairs =$("div[name=chair]");
		 for(var i =0;i<chairs.length;i++){
			 var x1 = $(chairs[i]).attr("x1");
			 var y1 = $(chairs[i]).attr("y1");
			 for(var j=0;j<data.length;j++){
				 if(x1==data[j].x1 && y1==data[j].y1){
					 $($(chairs[i]).children()[0]).css({"background":"url(${pageContext.request.contextPath}/image/user.png)"}); 
					 $($(chairs[i]).children()[1]).text(data[j].string1);
					 $($(chairs[i]).children()[1]).attr("title",data[j].string1);
				 }
			 }
		 } 
	 }
	 //选作
	 function selectChair(){
		$("div[name=chair]").click(function(){
			var object = new Object();
			object.x1=$(this).attr("x1");
			object.y1=$(this).attr("y1"); 
			object.table_id =$(this).attr("table_id");
			object.startClass =$(this).attr("startClass");
			
			var sys_class_id = $(this).attr("sys_class_id");
			 var url ="${pageContext.request.contextPath}/edu/sysClassAction.do?method=addStudentRoomOption";		  
			 $.ajax({
				   type: "POST",
				   url: url,
				   data:object,
				   async:false,
				   dataType:'json',
				   success: function(msg){  
				       alert(msg.message); 
				        $("#li"+sys_class_id).click();
				   }
			});  
		});
	 } 
	 //加载我的老师
	 function loadMyteacher(){
		 var url ="${pageContext.request.contextPath}/edu/sysUserAction.do?method=getStudent_Teacher_C";		  
			 $.ajax({
				   type: "POST",
				   url: url,
				   async:false,
				   dataType:'json',
				   success: function(msg){  
				     if(msg && msg.list && msg.list.length>0){
				    	  showMsg(msg);
				     }
				   }
			}); 
	 };
	 $(function(){
		
		 loadMyteacher();
	 });
 })();
 </script>